package com.gm.commonlib.filters;

import android.text.TextUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class RegexConstant {

    //TODO 8位整数部分(可有2位小数部分) => 可以只输入整数部分加上小数点
    public static final String MAX_MONEY_VALUE = "^[\\d]{1,8}([.][\\d]{0,2})?$";
    //TODO 最大5位整数(99999)、2位小数(99)
    public static final String MAX_MONEY_VALUE_52 = "^[\\d]{1,5}([.][\\d]{0,2})?$";
    //TODO 最大5位整数(99999)、3位小数(999)
    public static final String MAX_MONEY_VALUE_53 = "^[\\d]{1,5}([.][\\d]{0,3})?$";
    //TODO 最大7位整数(9999999)、2位小数(99)
    public static final String MAX_MONEY_VALUE_72 = "^[\\d]{1,7}([.][\\d]{0,2})?$";
    public static final String MAX_MONEY_VALUE_73 = "^[\\d]{1,7}([.][\\d]{0,3})?$";
    //TODO 最大7位整数(9999999)、2位小数(99)
    public static final String MAX_MONEY_VALUE_92 = "^[\\d]{1,9}([.][\\d]{0,2})?$";
    public static final String MAX_MONEY_VALUE_62 = "^[\\d]{1,6}([.][\\d]{0,2})?$";
    public static final String MAX_MONEY_VALUE_43 = "^[\\d]{1,4}([.][\\d]{0,3})?$";
    public static final String MAX_MONEY_VALUE_23 = "^[\\d]{1,2}([.][\\d]{0,3})?$";
    public static final String MAX_MONEY_VALUE_33 = "^[\\d]{1,3}([.][\\d]{0,3})?$";
    public static final String MAX_MONEY_VALUE_32 = "^[\\d]{1,3}([.][\\d]{0,2})?$";
    public static final String MAX_MONEY_VALUE_22 = "^[\\d]{1,2}([.][\\d]{0,2})?$";
    public static final String NUM_VALUE = "^[\\d]+([.][\\d]{0,2})?$";
    public static final String MAX_MONEY_VALUE_74= "^[\\d]{1,7}([.][\\d]{0,4})?$";
    public static final String MAX_MONEY_VALUE_64 = "^[\\d]{1,6}([.][\\d]{0,4})?$";
    public static final String MAX_MONEY_VALUE_54 = "^[\\d]{1,5}([.][\\d]{0,4})?$";
    public static final String MAX_MONEY_VALUE_42 = "^[\\d]{1,4}([.][\\d]{0,2})?$";
    public static final String MAX_MONEY_VALUE_BIG2 = "^[\\d]{1,8}([.][\\d]{0,2})?$";
    public static final String MAX_MONEY_VALUE_34 = "^[\\d]{1,3}([.][\\d]{0,4})?$";
    public static final String MAX_MONEY_VALUE_MAX92 = "^[\\d]{1,9}([.][\\d]{0,2})?$";


    public static final String MAX_MONEY_VALUE_MAX5 = "^[\\d]{1,5}$";
    public static final String MAX_MONEY_VALUE_MAX3 = "^[\\d]{1,3}$";
    public static final String MAX_MONEY_VALUE_MAX2 = "^[\\d]{1,2}$";


    /**
     * 空格正则表达式
     */
    public static final String Space_Regex = " ";


    /**
     * 以字母开始的正则表达式
     */
    public static final Pattern RegexStartWithCharacter = Pattern.compile("^([A-Za-z].*)$");

    /**
     * 数字正则表达式
     */
    public static final String NumberString_Regex = "^\\d+$";
    public static final String Code_Regex = "^\\d{6,20}$";

    public static final String LICENSE_PLATE = "^[\\u4e00-\\u9fa5][A-Za-z0-9]{2,7}+$";

    /**
     * 汉字正则表达式
     */
    public static final String ChinesWord = "^[\\u4e00-\\u9fa5]+$";
    public static final String REGEX_NOT_CHINESE = "^[^\\u4e00-\\u9fa5]+$";
    //中文和点
    public static final String REGEX_CHINESE_NAME = "^[•·.．\\u4e00-\\u9fa5]+$";

    public static final String RESULT_CHINESE_NAME = "^[•·.．\\u4e00-\\u9fa5]{2,10}+$";

    /**
     * 字母和数字正则表达式
     */
    public static final String EnglishAndDigit = "^[A-Za-z0-9]$";
    public static final String EnglishAndDigit6_20 = "^[A-Za-z0-9]{6,20}$";
    public static final String REGEX_INSURANCE_NUMBER = "^[A-Za-z0-9]+$";
    public static final String CHARATER_Regex = "^([A-Za-z0-9].*)$";
    //社会信用代码
    public static final String REGEX_COMPANY_CODE_1 = "^[A-Za-z0-9]{8}-[X0-9]$";
    public static final String REGEX_COMPANY_CODE_2 = "^[A-Za-z0-9]{18}$";

    public static final String Name_Regex = "^[•·.．\\u4e00-\\u9fa5]{2,20}$";

    public static final String CHINA_AND_NUMBER = "^[0-9•·.．\\u4e00-\\u9fa5]+$";

    public static final String Digit_Regex_EC = "^[A-Za-z\\u4e00-\\u9fa5]+$";
    /**
     * 中文，数字和英文
     */
    public static final String REGEX_ZH_NB_EN = "^[A-Za-z0-9\\u4e00-\\u9fa5]+$";
    /**
     * 换行回车正则表达式
     */
    public static final String Config_Regex = "^[A-Za-z0-9.+=\\-\\u4e00-\\u9fa5]+$";

    public static final String REGEX_SCHEMA_NCD = "^[A-Za-z0-9\\u4e00-\\u9fa5]+$";

    public static final String REGEX_SCHEMA_NCDD = "^[A-Za-z0-9\\u4e00-\\u9fa5\\.]+$";

    public static final String RoleOrProjectName_Regex = "^[A-Za-z0-9\\u4e00-\\u9fa5-—]+$";
    public static final String CarLiencePlatNo_Input_Regex = "^[A-Za-z0-9\\u4e00-\\u9fa5\\-]+$";

    public static final String queryCondition = "^[A-Za-z0-9·.•．\\u4e00-\\u9fa5——-]+$";
    /**
     * 地址规则
     */
    public static final String CompanyAddress_Regex = "^[A-Za-z0-9 ，,\\u4e00-\\u9fa5-—]+$";

    public static final String ProjectName_Regex = "^[A-Za-z0-9()（）\\u4e00-\\u9fa5-—]+$";
    /**
     * 汉字正则表达式
     */
    public static final String REGEX_Refund = "^[A-Za-z0-9 \\n\\r，。,.！!、“”\\u4e00-\\u9fa5一-]+$";

    public static final String ADDR_STRING = "^[A-Za-z0-9 \\n\\r，。,.！!、\\-“”一-龥]+$";

    public static final String REGEX_GROUP_INFO = "^[A-Za-z0-9 \\n\\r，。,.！!、~～?？“”()（）\\[\\]【】\\u4e00-\\u9fa5-—]+$";

    /**
     * base64的图片Data数据
     */
    public static final Pattern Base64DataUrl = Pattern.compile("^data:image/.*;base64,( )*.*$");

    /**
     * 换行回车正则表达式
     */
    public static final String Enter_Regex = "(.*((\\r+)|(\\n+)|(\\r\\n)+|(\\n\\r)+).*)";

    public static final String Contact_Regex = "^((\\d{2}-?)?\\d{9}|(\\d{3}-?)?\\d{8}|(\\d{4}-?)?\\d{7})(-(\\d{4}|\\d{3}|\\d{2}|\\d{1}))?$";

    public static final String CarLiencePlatNo_WithoutSplit_Regex = "^[\u4e00-\u9fa5][A-Za-z][A-Za-z0-9]{5,6}$";

    public static final String IDCard_Character = "^[0-9xX]{0,18}$";

    /**
     * 汉字正则表达式
     */
    public static final String Phone_Regex = "^(1[3456789][0-9]{9})$";

    public static final String REGEX_PHONE_SCHEMA = "^[Tt][Ee][Ll]:(.)*";

    public static final String ID_CARD_REG = "^(\\d{15}|\\d{18}|\\d{17}[Xx])$";

    public static final String URL_REG_TEXT = "^([Hh][Tt][Tt][Pp][Ss]{0,1}:.*)$";

    public static final String LEFT_LINE_TEXT = "\\\\";

    /**
     * 双引号，单引号、反引号正则表达式
     */
    public static final String QUETO_Regex = "(.*((‘)(’)|(”)|(“)|(\")|(\')|(`)).*)";
    /**
     * 双引号，单引号、反引号正则表达式
     */
    public static final String ChinesAndEnglishQUETO_Regex = "(.*((‘)|(’)|(”)|(“)|(\")|(\')|(`)).*)";
    public static final String CORRECT_NAME_TEXT = "^([\\u4e00-\\u9fa5][.．]?)*$|^([.．]?[\\u4e00-\\u9fa5])*$|^[.．]$";
    public static final String DOUBLE_QUOTATION_MARKS = "^*\"*$";
    public static final String NORMAR_INPUT = "^[\u2E80-\uFE4F\u0021-\u00FF\u3001-\u3015\uFF01-\uFF1F\u2014-\u201D]+$";

    public static final String DOUBLE_DOT_TEXT = ".*[.．]{2,}.*";

    public static final Pattern idCardUpperPattern = Pattern.compile(ID_CARD_REG);

    public static final Pattern Phone_RegexPattern = Pattern.compile(Phone_Regex);

    public static final Pattern URL_RegexPattern = Pattern.compile(URL_REG_TEXT);

    public static final Pattern DoubleDotRegexPattern = Pattern.compile(DOUBLE_DOT_TEXT);

    public static final boolean checkChainessResult(String value) {
        String resultValue = value.replaceAll("[.]", "");
        if (TextUtils.isEmpty(resultValue)) {
            return false;
        }
        return true;
    }

    public static boolean match(Pattern pattern, String text) {
        return pattern.matcher(text).matches();
    }

    public static class NumberHelper {

        public final static String NumberUnit = "((\\d*(\\.?\\d*))([a-zA-Z\\u4e00-\\u9fa5]*))";

        /**
         * 带单位的数据
         */
        public static Pattern NUMBER_WITH_UNIT = Pattern.compile(NumberUnit);

        public static void compile(String reg) {
            if (TextUtils.isEmpty(reg)) {
                NUMBER_WITH_UNIT = Pattern.compile(NumberUnit);
            } else {
                NUMBER_WITH_UNIT = Pattern.compile(reg);
            }
        }

        public static void reset() {
            NUMBER_WITH_UNIT = Pattern.compile(NumberUnit);
        }

        public static String defaultNumberFrom(String numberWithUnit) {
            Matcher matcher = NUMBER_WITH_UNIT.matcher(numberWithUnit);
            if (matcher.matches()) {
                return matcher.group(2);
            }
            return numberWithUnit;
        }

        public static String defaultUnitFrom(String numberWithUnit) {
            Matcher matcher = NUMBER_WITH_UNIT.matcher(numberWithUnit);
            if (matcher.matches()) {
                return matcher.group(4);
            }
            return numberWithUnit;
        }


        public static String getNumberFrom(String numberWithUnit, int group) {
            Matcher matcher = NUMBER_WITH_UNIT.matcher(numberWithUnit);
            if (matcher.matches()) {
                return matcher.group(group);
            }
            return numberWithUnit;
        }

        public static String getUnitFrom(String numberWithUnit, int group) {
            Matcher matcher = NUMBER_WITH_UNIT.matcher(numberWithUnit);
            if (matcher.matches()) {
                return matcher.group(group);
            }
            return numberWithUnit;
        }


        public static String getNumberFromString(String data) {
            String regEx = "[^0-9.]";
            Pattern p = Pattern.compile(regEx);
            Matcher m = p.matcher(data);
            return m.replaceAll("").trim();
        }

    }

}
